package com.sunwayhorizo.health.hl7.factories;

import com.sunwayhorizo.health.hl7.persistent.RimCoreRootMaster;

import java.util.Iterator;
import java.util.List;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;


@Stateless(mappedName = "RootMasterFactory")
@Remote(RootMasterRemote.class)
@Local(RootMasterLocal.class)
public class RootMasterFactory implements RootMasterRemote, RootMasterLocal {
    @PersistenceContext(unitName="sunwayhealth")
    private EntityManager em;
    private RimCoreRootMaster rootMaster;

    public RootMasterFactory() {
    }

    /** <code>select o from RimCoreRootMaster o</code> */
    public List<RimCoreRootMaster> queryRimCoreRootMasterFindAll() {
        return em.createNamedQuery("RimCoreRootMaster.findAll").getResultList();
    }
    
    public RimCoreRootMaster getRootMaster() {
        List result = queryRimCoreRootMasterFindAll();
        if (result != null )    {            
           Iterator iterator = result.iterator(); 
           while (iterator.hasNext()){
               rootMaster = (RimCoreRootMaster)iterator.next();  
               }            
        }
        return rootMaster;
    }
}
